import java.util.LinkedList;
import java.util.List;

//给定一个单链表，请设定一个函数，将链表的奇数位节点和偶数位节点分别放在一起，重排后输出。
//注意是节点的编号而非节点的数值
public class Solution {

      public class ListNode {
        int val;
        ListNode next = null;
        public ListNode(int val) {
          this.val = val;
        }
      }
    public ListNode oddEvenList (ListNode head) {
          if(head == null){
              return null;
          }
          if( head.next == null){
              return head;
          }
          ListNode odd = head;
          ListNode even = head.next;
          ListNode evenHead = even;
          while(even != null && even.next != null){
              odd.next = odd.next.next;
              even.next = even.next.next;
              odd = odd.next;
              even = even.next;
          }
          odd.next = evenHead;
        return head;
    }
}
